﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Windows.Forms;
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.Management.Nmo;
using Microsoft.SqlServer.Management.Common;
using Microsoft.SqlServer.Management.Trace;

namespace Entity
{
    public class HEDAOTAO
    {
        private String MAHDT, TENHDT;

        public String maHDT
        {
            get { return MAHDT; }
            set { MAHDT = value; }
        }
        public String tenHDT
        {
            get { return TENHDT; }
            set { TENHDT = value; }
        }
        /// <summary>
        /// 
        /// </summary>
        DataBaseAccess dataBaseAccess = new DataBaseAccess();

        public void hienthi_HeDaoTao(DataGridView dtgHeDaoTao)
        {
            try
            {
                DataTable dataTable = new DataTable();
                dataTable = dataBaseAccess.getDataTable("SELECT * FROM HEDAOTAO");
                dtgHeDaoTao.DataSource = dataTable;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Loi hien thi DataGridView \n" + ex.Message);
            }
        }

        public void them_HeDaoTao(HEDAOTAO hedaotao)
        {
            String excuteString = "INSERT INTO HEDAOTAO VALUES ('" + hedaotao.maHDT + "','" 
                                                                   + hedaotao.tenHDT + "')";
            dataBaseAccess.excuteNonQuery(excuteString);
        }

        public void sua_HeDaoTao(HEDAOTAO hedaotao)
        {
            String excuteString = "UPDATE HEDAOTAO SET TENHDT = '" + hedaotao.tenHDT + 
                                              "' WHERE MAHDT = '" + hedaotao.maHDT + "' ";
            dataBaseAccess.excuteNonQuery(excuteString);
        }

        public void xoa_HeDaoTao(String mahdt)
        {
            String excuteString = "DELETE FROM HEDAOTAO WHERE MAHDT = '" + mahdt + "' ";
            dataBaseAccess.excuteNonQuery(excuteString);
        }
    }
}
